public class NumberResource {

    private  Integer number=0;

    private Integer printIndex=0;

    public void add(){
        number++;
    }


    public Integer get(){
        return number;
    }

    public synchronized void showNumber() throws InterruptedException {
        if(printIndex>100)
            System.exit(0);
        Integer number1=this.get();
        add();
        Thread.sleep(5);
        Integer number2=this.get();
        if((number1+1)==number2){
            System.out.println(Thread.currentThread().getName()+"依次递增"+ " => 递增-- 正确--：" + number1 + " ***** " + number2);
        }else
            System.out.println(Thread.currentThread().getName()+"依次递增异常"+ " => 递增-- 正确--：" + number1 + " ***** " + number2);

        printIndex++;
    }



}

